<template>
    <div class="bg">
        <div class="select">
            <img src="@/assets/close.png" id="close" @click="close">
            <div class="title">选择收货地址</div>
            <div class="address-list" v-if="data.length >= 1">
                <div class="item"
                    v-for="item in data" :key="item._id"
                    @click="select(item)"
                >
                    <p class="address">{{item.address}}</p>
                    <div class="info">
                        <div class="name">{{item.name}}</div>
                        <div class="phone">{{item.phone}}</div>
                    </div>
                </div>
            </div>
            <div class="nullAddress" v-else-if="data.length <= 0">
                <router-link to='/addlocation'>暂时没有地址，点击去添加</router-link>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name:"SelectAddress-Settlement",
        props:['data'],
        data(){
            return {
               isOpen:false,
               
            }
        },
        methods: {
            // 发送关闭
            close(){
                this.isOpen = false
                this.$bus.$emit('close',this.isOpen)
            },
            select(item){
                localStorage.setItem('bugAddress',JSON.stringify(item))
                this.$router.go(0)
            }
            
        },
        mounted() {
            // 发送打开
            this.$bus.$on('open', isOpen => this.isOpen = isOpen)
        },

        beforeDestroy() {
            this.$bus.$off('open')
        },

    }
</script>

<style scoped lang="less">
    .nullAddress{
        a{
            display: block;
            width: 100%;
            margin-top: 50px;
            text-align: center;
            font-size: 18px;
        }
    }

    .bg{
        width: 100%;
        height: 100%;
        position: fixed;
        z-index: 10000;
        background: rgba(0, 0, 0, 0.164);
        top: 0;

        .select{
            width: 100%;
            height: 60%;
            background: #fff;
            border-radius: 15px;
            position: fixed;
            bottom: 0;
            left: 0;
            overflow-y:auto;

            .title{
                text-align: center;
                color: #333;
                // font-weight: 600;
                font-size: 16px;
                padding: 15px 0;
            }

            img{
                position: absolute;
                width: 20px;
                height: 20px;
                top: 10px;
                right: 10px;
            }
        }

        .address-list{

            .item{
                padding: 10px 25px;
                border-bottom: 1px solid rgb(248, 243, 243);
                .address{
                    font-size: 16px;
                    margin-bottom: 10px;
                    font-weight: 600;
                }

                .info{
                    display: flex;
                    font-size: 12px;
                    font-weight: 600;

                    .name{
                        margin-right: 20px;
                    }
                }
            }
        }


    }
</style>    